﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Molia.AppCenter.View
{
    public enum ApplicationCommandOption
    {
        close = 1,
        max,
        min
    }
    public class ApplicationCommand : CommandBinding
    {
        Action<object> _e;
        public ApplicationCommand(ApplicationCommandOption op)
        {
            switch (op)
            {
                case ApplicationCommandOption.close:
                    _e = this.Close;
                    break;
                case ApplicationCommandOption.max:
                    _e = this.Max;
                    break;
                case ApplicationCommandOption.min:
                    _e = this.Min;
                    break;
            }
        }
        public override void Execute(object parameter)
        {
            _e(parameter);
        }
        private void Close(object parameter)
        {
            var wnd = IsWindow(parameter);
            if (wnd != null)
            {
                wnd.Close();
            }
        }
        private void Max(object parameter)
        {
            var wnd = IsWindow(parameter);
            if(wnd != null)
            {
                if(wnd.WindowState == System.Windows.WindowState.Maximized)
                {
                    wnd.WindowState = System.Windows.WindowState.Normal;
                }
                else
                {
                    wnd.WindowState = System.Windows.WindowState.Maximized;
                }
            }
        }
        private void Min(object parameter)
        {
            var wnd = IsWindow(parameter);
            if(wnd != null)
            {
                wnd.WindowState = System.Windows.WindowState.Minimized;
            }
        }
        private System.Windows.Window IsWindow(object o)
        {
            if (o is System.Windows.Window)
            {
                return o as System.Windows.Window;
            }
            else
            {
                return null;
            }
        }
    }
}
